package com.sina.microblog.ut.utils
{
	import com.sina.microblog.MicroBlog;
	import com.ut.nm_test_internal;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	
	import flexunit.framework.Assert;
	
	use namespace nm_test_internal;
	
	public class URLRequestChecker
	{
		public function URLRequestChecker()
		{
		}
		public static function check(mb:MicroBlog, destReq:URLRequest, destData:String):void
		{
			var loader:URLLoader = mb.lastLoader;
			var req:URLRequest = mb.lastRequest;
			if ( destData != null)
			{
				loader.data = destData;
				loader.dispatchEvent(new Event(Event.COMPLETE));
			}
			Assert.assertEquals( destReq.url, req.url);
			Assert.assertEquals(destReq.method, req.method);
			if ( destReq.method == URLRequestMethod.POST)
			{
				var postData:Object = destReq.data;
				var data:Object = req.data;
				for (var key:String in postData )
				{
					Assert.assertEquals(postData[key], data[key]);
				}
			}		
			
			mb.lastLoader = null;
			mb.lastRequest = null;
		}
	}
}